import unittest
from autoframe.common.functions import open_browser
from autoframe.page.login_page import LoginPage
from autoframe.page.index_page import IndexPage


class LoginTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver = open_browser()
        # 创建了对象
        cls.login = LoginPage(driver)
        cls.index = IndexPage(driver)

    def test_01_login(self):
        # 输入网址
        self.login.get('https://ecshop.test2.shopex123.com/user.php')
        # 输入账号
        self.login.input_username('aaabbb')
        # 输入密码
        self.login.input_password('Aa123456')
        # 点击记住登录信息按钮
        self.login.remember()
        # 点击登录
        self.login.btn_login()

        # 断言登录成功
        username = self.index.font_text()
        self.assertEqual('aaabbb', username)

    @classmethod
    def tearDownClass(cls) -> None:
        # 关闭浏览器
        cls.login.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
